const uploadService = require("../services/upload.mjs");

/**
 * 上传图片
 * @param {*} ctx
 */
exports.imgUpload = async (ctx) => {
    let file = ctx.request.files.file;
    if (!file) {
        ctx.status = 400;
        ctx.body = {
            code: "02",
            message: "参数异常！"
        };
        return;
    }
    esmModule = await import("../services/upload.mjs");
    await esmModule.imgUpload(file);

    ctx.body = {
        code: "00",
        message: "upload success",
        data: {
            path: `/uploads/images/${ctx.request.files.file.newFilename}`
        }
    };
};
